# -*- coding:utf-8 -*-
import cv2 as cv
import numpy as np
import sys

if __name__ == '__main__':
    # 读取图像并判断是否读取成功
    img = cv.imread(r"E:\studylife\detectflaws\code\imgEnhance\img.jpg")
    if img is None:
        print('Failed to read lena.jpg.')
        sys.exit()
    gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
    # 灰度图像二值化
    _, gray_B = cv.threshold(gray, 181, 255, cv.THRESH_BINARY)
    # _, gray_B_V = cv.threshold(gray, 125, 255, cv.THRESH_BINARY_INV)
    cv.imshow('gray_B', gray_B)
    # cv.imshow('gray_B_V', gray_B_V)
    # # 灰度图像TOZERO变换
    # _, gray_T = cv.threshold(gray, 125, 255, cv.THRESH_TOZERO)
    # _, gray_T_V = cv.threshold(gray, 125, 255, cv.THRESH_TOZERO_INV)
    # cv.imshow('gray_T', gray_T)
    # cv.imshow('gray_T_V', gray_T_V)
    # # 灰度图像TRUNC变换
    # _, gray_TRUNC = cv.threshold(gray, 125, 255, cv.THRESH_TRUNC)
    # cv.imshow('gray_TRUNC', gray_TRUNC)

    cv.waitKey(0)
    cv.destroyAllWindows()
